<?
require("session.php");
require("header.php");
?>
<script src="js/jquery-1.9.1.min.js"></script>
<link href="css/home.css" type="text/css" rel="stylesheet" />
<style>
	.input_text { width:260px; height:23px; border:#99cc33 1px solid; font-size:15px; font-family:arial; color:#ff3300}
</style>
</head>
<body style="margin:0px;background:white;" onload="$('#mobile').focus()">
	<? require("top.php"); ?>
	<div style="width:100%;background:#efefef;border-top:#ddd 5px solid; border-bottom:#ddd 5px solid">
		<div style="width:900px;text-align:center; background:white; margin:auto">
			<table width=99% cellpadding=3 cellspacing=1 bgcolor="#dddddd">
				<tr bgcolor=white><td colspan=2 align=left><font style="color:gray; font-size:15px">【<b>基本信息</b>】</font></td></tr>
				<tr bgcolor="white">
					<td align=left colspan="2" style="padding-bottom:20px">　<font color=red><?echo $_SESSION['truename']?></font>，您在本站的累计消费金额 <font color=red><?echo $_SESSION['total_money']?></font> 元，积分 <font color=red><?echo $_SESSION['total_score']?></font> 点，定单 <font color=red><?echo $_SESSION['order_count']?></font> 个，登录 <font color=red><?echo $_SESSION['login_count']?></font> 次，上次登录时间：<font color=gray><?echo $_SESSION['last_login']?></font>
					</td>
				</tr>
				<tr bgcolor=white><td colspan=2 align=left><font style="color:gray; font-size:15px">【<b>个人资料</b>】</font></td></tr>
				<tr bgcolor="white">
					<td align=right  width=30%>登录账号</td><td align=left width=70%><input type="text" class="input_text" value="<?echo $_SESSION['mobile']?>" readonly style="background:#eee"></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>真实姓名</td><td align=left><input type="text" class="input_text" value="<?echo $_SESSION['truename']?>" id="truename"></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>联系地址</td><td align=left><input type="text" class="input_text" value="<?echo $_SESSION['address']?>" id="address"></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>所在区域</td><td align=left><select class="input_text" id="area"><option value=''>长沙市</option><option value='芙蓉区'>芙蓉区</option><option value='天心区'>天心区</option><option value='雨花区'>雨花区</option><option value='岳麓区'>岳麓区</option><option value='开福区'>开福区</option><option value='望城区'>望城区</option><option value='望城区'>长沙县</option><option value='望城区'>宁乡县</option><option value='浏阳市'>浏阳市</option></select></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>&nbsp;</td><td align=left><a href="javascript:modify_info()"><img src="images/save_button.jpg" id="btn_modify_info" border=0></a></td>
				</tr>
				<tr bgcolor=white><td colspan=2 align=left><font style="color:gray; font-size:15px">【<b>修改密码</b>】</font></td></tr>
				<tr bgcolor="white">
					<td align=right>当前密码</td><td align=left><input type="password" class="input_text" id="login_pass" style="font-size:25px"></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>新设密码</td><td align=left><input type="password" class="input_text" id="new_pass" style="font-size:25px"></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>确认密码</td><td align=left><input type="password" class="input_text" id="confirm_pass" style="font-size:25px"></td>
				</tr>
				<tr bgcolor="white">
					<td align=right>&nbsp;</td><td align=left><a href="javascript:modify_pwd()"><img src="images/save_button.jpg" id="btn_modify_pwd" border=0></a></td>
				</tr>
			</table>
			<br>
			<br>
		</div>
	</div>
	<script>
		$("#area").val("<?echo $_SESSION['area']?>");


		function modify_info() {
			if( $("#truename").val() == "" || $("#address").val() == "") {
				alert("请输入您的真实姓名及联系地址！");
				return false;
			}
			var params = {'truename':$("#truename").val(), 'address':$("#address").val(), 'area':$("#area").val()}
			if(confirm("确认要修改您的个人资料吗？")) {
				$("#btn_modify_info").attr("src", "images/saving_button.jpg");
				$.post("user_query.php?action=modify_info", params, function(data) {
					if(data == "ok") {
						alert("您的个人资料已成功修改！");
					} else {
						alert("操作失败!")
					}
					$("#btn_modify_info").attr("src", "images/save_button.jpg");
				});
			}
		}
	

		function modify_pwd() {
			if( $("#login_pass").val() == "" || $("#new_pass").val() == "") {
				alert("请输入当前的用户密码及新设密码！");
				return false;
			}
			if( $("#confirm_pass").val() != $("#new_pass").val()) {
				alert("新设密码二次确认不一致，请重试！");
				return false;
			}
			var params = {'login_pass':$("#login_pass").val(), 'new_pass':$("#new_pass").val()};
			$("#btn_modify_pwd").attr("src", "images/saving_button.jpg");
			$.post("user_query.php?action=modify_password", params, function(data) {
				if(data == "ok") {
					alert("您的密码已成功修改！");
					$("#login_pass").val('');
					$("#new_pass").val('');
					$("#confirm_pass").val('');

				} else if(data == "pwd_incorrect") {
					alert("当前用户密码验证失败，请确认后重试！");

				} else {
					alert("操作失败!")
				}
				$("#btn_modify_pwd").attr("src", "images/save_button.jpg");
			});
		}
	
	</script>
	<? require("bottom.php"); ?>

</body>
</html>